function RegisterAssistant() {
	this.urls = {
		bosh: '/xmpp-httpbind',
		register: '/epic/users/register.json'
	};

	this.models = {};
	this.models.servers = {
		label: 'server',
		modelProperty: 'value',
		choices: [
			{ label: 'hendl', value: 'blindeshendl.cg.tuwien.ac.at' },
			{ label: 'psi', value: '10.0.2.2' },
			{ label: 'vmware', value: '10.0.2.232' }
		]
	};
	var selected = this.models.servers.choices[1]; 

	this.models.server = { value: selected.value };
	this.models.admin = { label: 'Admin', value: 'admin@' + selected.label };
	this.models.button = { label: 'Register' };
}

RegisterAssistant.prototype.onError = function() {
	say('onError');
};

RegisterAssistant.prototype.mockRegisterSucesss = function() {
	this.models.server.value = this.models.servers.choices[1].value;
	this.onSuccess({user: { name: 'test' }});
	c.get('button').mojo.deactivate();
};



RegisterAssistant.prototype.onRegister = function() {
	var c = this.controller, models = this.models, urls = this.urls, doc = c.document;
	var url = 'http://' + models.server.value + urls.register;
	say('onRegister: ' + url);

	jQuery('#register form',doc).submit();

//	xhr.send('');
//	jQuery.ajax({
//		url: url,
//		type: 'post',
//		data: {},
//		success: this.onSuccess.bind(this),
//		error: function() { say('error'); },
//		complete: function() { say('complete'); c.get('button').mojo.deactivate(); }
//	});
};

RegisterAssistant.prototype.pushStatus = function() {
	var c = this.controller;
	c.stageController.popScene(null);
	var appCtr = Mojo.Controller.getAppController();
	appCtr.closeStage(appCtr.assistant.stages.register.name);
	appCtr.assistant.handleLaunch({
		source: 'register-success'
	});
};
RegisterAssistant.prototype.onSuccess = function(data) {
	var user = data.user, host = this.models.server.value, admin = this.models.admin.value;
	var domain = jQuery.grep(this.models.servers.choices, function(item) {
		if (item.value == host) { return item; }
	})[0].label;

	say('onSuccess: '  + user.name);
	utils.set('id', user.id);
	utils.set('user', user.name);
	utils.set('domain', domain);
	utils.set('host', host);
	utils.set('admin', admin);
	this.controller.showAlertDialog({
		onChoose: this.pushStatus,
		title: 'Registration Sucessfull',
		message: 'Node registered on ' + domain,
		choices: [
			{ label: 'Status', value: 'status' }
		]
	});

//	var appCtr = Mojo.Controller.getAppController();
//	appCtr.assistant.handleLaunch({
//		source: 'register-success'
//	});

	//update info on screen
	// successfully registered users bla
	//  - optionally send email
};

RegisterAssistant.prototype.setup = function() {
	say('RegisterAssistant.setup');
	var c = this.controller, models = this.models, e = Mojo.Event, doc = c.document;
	c.setupWidget('servers', models.servers, models.server);
	c.setupWidget('admin', {}, models.admin);
	c.setupWidget('button', { type: Mojo.Widget.activityButton }, models.button );
	e.listen(c.get('button'), e.tap, this.onRegister.bind(this));

//	var iframe = '<iframe><form method="POST"></form></iframe>';
//	jQuery('#register', doc).append(iframe);
//	jQuery('#register form',doc).attr('action', 'http://10.0.2.2:3000/users');
};


RegisterAssistant.prototype.activate = function(event) {
	/* put in event handlers here that should only be in effect when this scene is active. For
	   example, key handlers that are observing the document */
};

RegisterAssistant.prototype.deactivate = function(event) {
	/* remove any event handlers you added in activate and do any other cleanup that should happen before
	   this scene is popped or another scene is pushed on top */
};

RegisterAssistant.prototype.cleanup = function(event) {
	/* this function should do any cleanup needed before the scene is destroyed as 
	   a result of being popped off the scene stack */
};
